﻿package mortal.game.resource.tableConfig
{
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.view.closedBetaGiftBagNew.group.*;

    public class ClosedBetaGiftBagConfig extends Object
    {
        private var _levelGiftDic:Dictionary;
        private var _onlineGiftDic:Dictionary;
        private var _timingGiftDic:Dictionary;
        private static var _instance:ClosedBetaGiftBagConfig;

        public function ClosedBetaGiftBagConfig()
        {
            if (_instance != null)
            {
                throw new Error(" ClosedBetaGiftBagConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_agency_award_config.json");
            this.write(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            var _loc_4:Object = null;
            if (!this._levelGiftDic)
            {
                this._levelGiftDic = new Dictionary();
            }
            if (!this._onlineGiftDic)
            {
                this._onlineGiftDic = new Dictionary();
            }
            if (!this._timingGiftDic)
            {
                this._timingGiftDic = new Dictionary();
            }
            for each (_loc_4 in param1)
            {
                
                _loc_2 = _loc_4;
                _loc_3 = _loc_2.id;
                switch(_loc_2.type)
                {
                    case 1:
                    {
                        this._levelGiftDic[_loc_3] = _loc_2;
                        break;
                    }
                    case 2:
                    {
                        this._onlineGiftDic[_loc_3] = _loc_2;
                        break;
                    }
                    case 3:
                    {
                        this._timingGiftDic[_loc_3] = _loc_2;
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            return;
        }// end function

        public function get levelGiftGroup() : Vector.<ClosedBetaLevelGiftGroup>
        {
            var group:ClosedBetaLevelGiftGroup;
            var o:Object;
            var sortFunc:Function;
            var vec:* = new Vector.<ClosedBetaLevelGiftGroup>;
            var _loc_2:int = 0;
            var _loc_3:* = this._levelGiftDic;
            while (_loc_3 in _loc_2)
            {
                
                o = _loc_3[_loc_2];
                group = new ClosedBetaLevelGiftGroup();
                group.level = o.condition;
                group.receiveNum = o.goldNum;
                group.receiveType = ClosedBetaBaseGroup.CanReceive;
                if (o.goldNum == 200)
                {
                    group.textType = 1;
                }
                else if (o.goldNum == 300)
                {
                    group.textType = 2;
                }
                else if (o.goldNum == 600)
                {
                    group.textType = 3;
                }
                else
                {
                    group.textType = 0;
                }
                vec.push(group);
            }
            sortFunc = function (param1:ClosedBetaLevelGiftGroup, param2:ClosedBetaLevelGiftGroup) : Number
            {
                if (param1 == null || param1 == null)
                {
                    return 1;
                }
                if (param1.level > param2.level)
                {
                    return 1;
                }
                if (param1.level < param2.level)
                {
                    return -1;
                }
                return 0;
            }// end function
            ;
            vec.sort(sortFunc);
            return vec;
        }// end function

        public function get onlineGiftGroup() : Vector.<ClosedBetaOnlineGiftGroup>
        {
            var group:ClosedBetaOnlineGiftGroup;
            var o:Object;
            var sortFunc:Function;
            var vec:* = new Vector.<ClosedBetaOnlineGiftGroup>;
            var _loc_2:int = 0;
            var _loc_3:* = this._onlineGiftDic;
            while (_loc_3 in _loc_2)
            {
                
                o = _loc_3[_loc_2];
                group = new ClosedBetaOnlineGiftGroup();
                group.onlineTime = o.condition;
                group.receiveNum = o.goldNum;
                group.receiveType = ClosedBetaBaseGroup.CanReceive;
                vec.push(group);
            }
            sortFunc = function (param1:ClosedBetaOnlineGiftGroup, param2:ClosedBetaOnlineGiftGroup) : Number
            {
                if (param1 == null || param1 == null)
                {
                    return 1;
                }
                if (param1.onlineTime > param2.onlineTime)
                {
                    return 1;
                }
                if (param1.onlineTime < param2.onlineTime)
                {
                    return -1;
                }
                return 0;
            }// end function
            ;
            vec.sort(sortFunc);
            return vec;
        }// end function

        public function get timingGiftGroup() : Vector.<ClosedBetaTimingGiftGroup>
        {
            var group:ClosedBetaTimingGiftGroup;
            var o:Object;
            var sortFunc:Function;
            var i:int;
            var str:String;
            var arr_YMD_HMS:Array;
            var arr_H_M_S:Array;
            var startDt:int;
            var endDt:int;
            var vec:* = new Vector.<ClosedBetaTimingGiftGroup>;
            var _loc_2:int = 0;
            var _loc_3:* = this._timingGiftDic;
            while (_loc_3 in _loc_2)
            {
                
                o = _loc_3[_loc_2];
                group = new ClosedBetaTimingGiftGroup();
                str = o.startDt;
                arr_YMD_HMS = str.split(" ");
                arr_H_M_S = String(arr_YMD_HMS[1]).split(":");
                startDt = int(arr_H_M_S[0]) * 60 + int(arr_H_M_S[1]);
                str = o.endDt;
                arr_YMD_HMS = str.split(" ");
                arr_H_M_S = String(arr_YMD_HMS[1]).split(":");
                endDt = int(arr_H_M_S[0]) * 60 + int(arr_H_M_S[1]);
                group.startDt = startDt;
                group.endDt = endDt;
                group.receiveNum = o.goldNum;
                group.receiveType = ClosedBetaBaseGroup.CanReceive;
                vec.push(group);
            }
            sortFunc = function (param1:ClosedBetaTimingGiftGroup, param2:ClosedBetaTimingGiftGroup) : Number
            {
                if (param1 == null || param1 == null)
                {
                    return 1;
                }
                if (param1.startDt > param2.startDt)
                {
                    return 1;
                }
                if (param1.startDt < param2.startDt)
                {
                    return -1;
                }
                return 0;
            }// end function
            ;
            vec.sort(sortFunc);
            i;
            while (i < vec.length)
            {
                
                vec[i].bmpType = i + 1;
                i = (i + 1);
            }
            return vec;
        }// end function

        public static function get instance() : ClosedBetaGiftBagConfig
        {
            if (_instance == null)
            {
                _instance = new ClosedBetaGiftBagConfig;
            }
            return _instance;
        }// end function

    }
}
